package com.hejjon.syyapi.service.impl;

import com.hejjon.syyapi.bean.ConnectionInfo;
import com.hejjon.syyapi.service.IJDBCService;
import com.hejjon.syyapi.util.JDBCUtil;
import com.kern.framework.bean.ResponseResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.sql.Connection;

/**
 * Created by caoshi at 22:00 2021-10-12
 */
@Service
public class JDBCServiceImpl implements IJDBCService {

    private static Logger logger = LoggerFactory.getLogger(JDBCServiceImpl.class);

    @Override
    public ResponseResult testConnection(ConnectionInfo connInfo) {
        Connection conn = JDBCUtil.getConnection(connInfo);

        if (conn == null) {
            logger.info("获取连接失败");
            return new ResponseResult(0, "获取数据库连接失败", "error", null);
        } else {
            logger.info("获取连接成功");
            return new ResponseResult(0, "获取连接成功", "success", null);
        }
    }
}
